package com.zndroid.logcat;

import androidx.annotation.ColorRes;

import com.zndroid.logcat.displayer.LogLevel;

import java.util.HashMap;

/**
 * Created by lzy on 2021/1/14.
 * config for LogcatX
 */
public class Config {
    public static final String LOG_SHOW_FORMAT = "%s %s-%s/%s \n%s/%s: %s";
    public static final String LOG_SAVE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String LOG_FILE_NAME = "_logcat.log";
    public static String LOG_SAVE_DIR = "";

    private static final HashMap<String, Integer> LOGCAT_COLORS = new HashMap<String, Integer>() {
        {
            put(LogLevel.ASSERT, R.color.color_logcat_assert);
            put(LogLevel.VERBOSE, R.color.color_logcat_verbose);
            put(LogLevel.DEBUG, R.color.color_logcat_debug);
            put(LogLevel.WARNING, R.color.color_logcat_warning);
            put(LogLevel.INFO, R.color.color_logcat_info);
            put(LogLevel.ERROR, R.color.color_logcat_error);
        }
    };

    @ColorRes
    public static int getColorRes(String priority) {
        return LOGCAT_COLORS.get(priority);
    }

    /**
     * 指定日志保存根目录，默认在"data/data/your_app_package_name/files"路径下
     * 注意：如果是外部存储权限请首先申请存储权限，框架内部不实现权限申请，只做判断
     * @param dir 日志保存路径
     * */
    public void setLogSavePath(String dir) {
        LOG_SAVE_DIR = dir;
    }

    public void setLogcatColors(@LogLevel String level, @ColorRes int colorId) {
        LOGCAT_COLORS.put(level, colorId);
    }
}
